import request from '@/utils/request'
import type { AxiosPromise } from "axios"
import type { otd, risk,qc,store,order,reservation } from '@/types/data'

/**
 * OTD列表
 * @returns 
 */
export function getOTDApi(): AxiosPromise<otd> {
    return request({
        url: 'api/otd',
        method: 'get'
    })
}

/**
 * 风险提醒
 * @returns 
 */
export function getRiskApi(openid:string): AxiosPromise<risk[]> {
    return request({
        url: 'api/risk',
        method: 'get',
        params:{
            openid:openid
        }
    })
}

/**
 * 质检不合格
 * @returns 
 */
export function getQcApi(openid:string): AxiosPromise<qc[]> {
    return request({
        url: 'api/qc',
        method: 'get',
        params:{
            openid:openid
        }
    })
}

/**
 * 订单到期情况统计
 * @returns 
 */
export function getStoreApi(openid:string): AxiosPromise<store[]> {
    return request({
        url: 'api/store',
        method: 'get',
        params:{
            openid:openid
        }
    })
}

/**
 * 订单详情
 * @returns 
 */
export function getBillApi(rcvid:string): AxiosPromise<order> {
    return request({
        url: 'api/detail',
        method: 'get',
        params:{
            rcvid:rcvid
        }
    })
}

/**
 * 获取客户送货窗口，无窗口无法送货
 * @returns 
 */
export function getWindowApi(openid:string): AxiosPromise<string> {
    return request({
        url: 'api/window',
        method: 'get',
        params:{
            openid:openid
        }
    })
}

/**
 * 获取送货时段
 * @returns 
 */
export function getWindowTimesApi(window:string,date:string): AxiosPromise<reservation[]> {
    return request({
        url: 'api/times',
        method: 'get',
        params:{
            window:window,
            date:date
        }
    })
}

/**
 * 保存预约记录
 * @param id 
 * @param openid 
 * @param window 
 * @param date 
 * @returns 
 */
export function setResverationApi(id:string,openid:string,window:string,date:string):AxiosPromise<string>{
    return request({
        url: 'api/reservation',
        method: 'post',
        params:{
            id:id,
            openid:openid,
            window:window,
            date:date
        }
    })
}

/**
 * 预约记录
 * @param openid 
 * @returns 
 */
export function getResverationApi(openid:string,pageindex:number):AxiosPromise<reservation[]>{
    return request({
        url: 'api/reservationlist',
        method: 'get',
        params:{
            openid:openid,
            pageIndex:pageindex,
            pageSize:4
        }
    })
}